package com.example.ssm.basic.mybatis;

import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.spring.SqlSessionFactoryBean;

import javax.sql.DataSource;

public class SelfDefSqlSessionFactoryBean extends SqlSessionFactoryBean {

    public SelfDefSqlSessionFactoryBean(){}

    @Override
    protected SqlSessionFactory buildSqlSessionFactory() throws Exception {
        SqlSessionFactory sqlSessionFactory = super.buildSqlSessionFactory();

        Configuration configuration = sqlSessionFactory.getConfiguration();
        //防止传入值为null时，提示 无效的列类型
        configuration.setJdbcTypeForNull(JdbcType.NULL);

        return sqlSessionFactory;
    }

    @Override
    public void setDataSource(DataSource dataSource) {
        super.setDataSource(dataSource);
    }
}
